package Jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

/**
 * Jsoup中Parse解析方法的重载
 * parse:解析html或xml文档，返回Document
 *   - parse(File in,String charsetName):通过文件的路径获取解析
 *   - parse(String html)：通过html源码进行获取解析
 *   - parse(URL url,int timeoutMillis):通过网络URL地址进行获取解析
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-17-18:04 18:04
 */
public class JsoupParse {
    public static void main(String[] args) throws URISyntaxException, IOException {
        //1.parse(File in,String charsetName)
        String path = JsoupParse.class.getClassLoader().getResource("student.xml").toURI().getPath();
        Document parse1 = Jsoup.parse(new File(path), "utf-8");
        //System.out.println(parse1);
        //2.parse(String html)
        Document parse2 = Jsoup.parse("<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <title>Title</title>");
        //System.out.println(parse2);
        //3.parse(URL url,int timeoutMillis) baseUri:表示在10秒内进行解析，超时解析失败
        Document parse3 = Jsoup.parse("https://www.baidu.com/", "10000");
        System.out.println(parse3);
    }
}
